﻿
pages_paymentIn_ItemIn = {
    gateWayId: 0,
    
    m_objPageItem: new Paging("divItemPaging", "pages_paymentIn_ItemIn.bindData", "pagingCss", 10, 5),

    documentReady: function() {
        this.bindData(1, this.m_objPageItem.pageSize);
    },

    bindData: function(_cur, _ps) {
        Loading.showProcess();
        $.ajax({
            type: "GET",
            url: "/Handler/Pages/ItemHandler.ashx",
            data: { paymentGatewayId: this.gateWayId, currentPage: _cur, pageSize: _ps, t: "GetListItemIn" },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Loading.closeProcess();
                pages_paymentIn_ItemIn.processData(data, _cur);
            }
        });

    },

    processData: function(data, _cur) {
        $("#divListItem").setTemplateURL("/Templates/paymentIn/itemin.htm");
        $("#divListItem").processTemplate(data);
        pages_paymentIn_ItemIn.m_objPageItem.bindPaging(_cur, data.TotalRecord);
        if (data.TotalRecord <= pages_paymentIn_ItemIn.m_objPageItem.pageSize) {
            $("#divItemPaging").attr('style', 'display:none');
        } else {
            $("#divItemPaging").attr('style', 'display:block');
        }
    }
};
$("#aBuyItem").live('click', function () {
    Loading.showProcess();
    var id = $(this.parentNode).attr("id").substring(4);
    var _data = {
        id: id,
        gateWayId: pages_paymentIn_ItemIn.gateWayId
    };
    $.ajax({
        type: "POST",
        url: "/Service/WSUser.asmx/GoBuyItemIn",
        data: JSON.encode(_data),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function (data) {
            Loading.closeProcess();
            var rel = data.d.split('|')[0];
            var mess = data.d.split('|')[1];
            if (rel == -1) {
                alert("bạn chưa đăng nhập");
                return;
            }
            if (rel > 0) {
                alert("Bạn đã mua thành công");
                return;
            } else {
                alert(mess);
            }
        }
    });

});

$("#btnBuyItemInSingle").live('click', function () {
    Loading.showProcess();
    var money = $("#txtNumAmount").val();
    var _data = {
        money: money,
        gateWayId: pages_paymentIn_ItemIn.gateWayId
    };
    $.ajax({
        type: "POST",
        url: "/Service/WSUser.asmx/GoBuyItemSingle",
        data: JSON.encode(_data),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function (data) {
            Loading.closeProcess();
            var rel = data.d.split('|')[0];
            var mess = data.d.split('|')[1];
            if (rel == -1) {
                alert("bạn chưa đăng nhập");
                return;
            }
            if (rel > 0) {
                alert("Bạn đã mua thành công");
                return;
            } else {
                alert(mess);
            }
        }
    });

});